diff options
| author | Adam Soltys <[email protected]> | 2023-01-27 20:58:08 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-27 20:58:08 -0800 |
| commit | 6e86789b9e61a63d87c0809fe963f51f4bfd22d8 (patch) | |
| tree | 7f3dc97f2b37b06c8193183f611b5b5abcb0f5e7 /src/routes/(app)/ln/[lnurl]/+page.server.js | |
| parent | 41b95b7f0da3108ce7e48d0af7b437898ae47d91 (diff) | |
| download | coinos-ui-6e86789b9e61a63d87c0809fe963f51f4bfd22d8.tar.gz coinos-ui-6e86789b9e61a63d87c0809fe963f51f4bfd22d8.zip | |
lnurlw
Diffstat (limited to 'src/routes/(app)/ln/[lnurl]/+page.server.js')
| -rw-r--r-- | src/routes/(app)/ln/[lnurl]/+page.server.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.js b/src/routes/(app)/ln/[lnurl]/+page.server.js index 6f61143f..a947dbb4 100644 --- a/src/routes/(app)/ln/[lnurl]/+page.server.js +++ b/src/routes/(app)/ln/[lnurl]/+page.server.js @@ -5,7 +5,8 @@ export async function load({ params }) { try { let { lnurl } = params; let data = await get(`/decode?text=${lnurl}`); - if (data.tag !== 'payRequest') throw error(500, 'We can only handle lnurl pay requests'); + if (data.tag === 'payRequest') throw redirect('/lnurlp'); + throw error(500, 'We can only handle lnurl pay requests'); return data; } catch (e) { throw error(500, e.message); @@ -13,7 +14,7 @@ export async function load({ params }) { } export const actions = { - default: async ({ cookies, fetch, request }) => { + pay: async ({ cookies, fetch, request }) => { let error; let { callback, amount, minSendable, maxSendable } = Object.fromEntries( @@ -26,5 +27,27 @@ export const actions = { let { pr } = await fetch(`${callback}?amount=${amount}`).then((r) => r.json()); throw redirect(307, `/send/lightning/${pr}`); + }, + + withdraw: async ({ cookies, fetch, request }) => { + let error; + + let { callback, amount, minWithdrawable, maxWithdrawable, k1 } = Object.fromEntries( + await request.formData() + ); + + if (amount < minWithdrawable) error = `Amount must be at least ${minWithdrawable} sats`; + if (amount > maxWithdrawable) error = `Amount must be at most ${maxWithdrawable} sats`; + if (error) return fail(400, { error }); + + let invoice = { amount, type: 'lightning' }; + let user = { username: form.get('username'), currency: form.get('currency') }; + + let { text: pr } = await post('/invoice', { invoice, user }, auth(cookies)); + + let c = callback.includes('?') ? '&' : '?'; + await fetch(`${callback}${c}k1=${k1}&pr=${pr}`).then((r) => r.json()); + + throw redirect(307, `/ln/withdrawal/sent`); } }; |
